import path from 'path'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import webpack from 'webpack' // 添加webpack核心模块

export default {
  mode: 'development',
  entry: './web/src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve('./web/dist'),
    clean: true
  },
  devServer: {
    static: path.resolve('./web/dist'),

    hot: true,
    liveReload: true,
    open: true,
    port: 8080,
    proxy: [
      {
        context: ['/api/**'],
        target: 'http://localhost:3000',
        changeOrigin: true
      }
    ],
    client: {
      overlay: true,
      progress: true
    },
    watchFiles: ['web/src/**/*']
  },
  module: {
    rules: [
      {
        test: /\.less$/i,
        use: [
          'style-loader',
          'css-loader',
          'less-loader'
        ],
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env'],
            plugins: ['istanbul']
          }
        }
      }
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './web/src/index.html',
      filename: 'index.html'
    }),
    new webpack.HotModuleReplacementPlugin()
  ],
  resolve: {
    extensions: ['.js', '.less'],
  },
}